package com.eaoa.uc.busorder.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.eaoa.base.EABaseAction;
import com.eaoa.constants.AttachmentConstants;
import com.eaoa.constants.BusOrderConstants;
import com.eaoa.query.bus.BusOrderQuery;
import com.eaoa.utils.AttachmentUtils;
import com.eaoa.vo.bus.BusOrder;
import com.stony.core.util.CoreUtils;

public class BusOrderViewAction extends EABaseAction{

	protected ActionForward doWork(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		Long orderno = CoreUtils.parseLong(request.getParameter("orderno"));
		
		String type = request.getParameter("type");
		
		BusOrder order = BusOrderQuery.loadByNo(orderno);
		
		request.setAttribute("result", order);
		
		if(orderno!=null){
			Map attachments = AttachmentUtils.getAttachmentMap(AttachmentConstants.ATTACHMENTTYPE_ORDER,orderno);
			request.setAttribute("attachments", attachments);
		}
		
		if(type!=null && type.equals("print")){
			if(order.getOrdertype()!=null){
				if(order.getOrdertype().equals(BusOrderConstants.TYPE_LDYS)){
					return mapping.findForward("print_ldys");
				}else if(order.getOrdertype().equals(BusOrderConstants.TYPE_THRC)){
					return mapping.findForward("print_thrc");
				}else if(order.getOrdertype().equals(BusOrderConstants.TYPE_ZCYS)){
					return mapping.findForward("print_zcys");
				}
			}else{
				return mapping.findForward("print");
			}
		}
		
		return mapping.findForward("success");
	}
}